package com.thkj.business.hikcammera.controller;

import com.thkj.service.TblIndividualService;
import com.thkj.util.RequestUtil;
import dp.R;
import com.thkj.framework.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 海康控制器
 */
@RestController
@RequestMapping("/backstage/hikorigin")
public class HikOriginController extends BaseController {

    @Autowired
    TblIndividualService tblIndividualService;

    @RequestMapping("")
    public ModelAndView index() {
        return new ModelAndView("hikorigin/list");
    }

    @RequestMapping("/query")
    public R query(HttpServletRequest request) {
        Map<String, Object> param = RequestUtil.getParameterMap(request);
        System.out.println("huang===param==" + param.toString());
        String parentIndexCode = (String) param.get("parentIndexCode");
        String treeCode = (String) param.get("treeCode");
        String name = (String) param.get("searchStr");

        List<Map> list = HikCamerasResoures.getHikDistrictRes(parentIndexCode, treeCode, name);
        return R.success(list);
    }

    @RequestMapping("/districtList")
    public R districtList(HttpServletRequest request) {
        List<Map> list = HikCamerasResoures.getHikDistrict();
        return R.success(list);
    }

    @RequestMapping("/cameras")
    public R apply(@RequestParam("pageNo") Integer pageNo,
                   @RequestParam("pageSize") Integer pageSize,
                   @RequestParam("regionIndexCode") String regionIndexCode) {
        CamerasRequest camerasRequest = new CamerasRequest();
        camerasRequest.setPageNo(pageNo);
        camerasRequest.setPageSize(pageSize);
        camerasRequest.setRegionIndexCode(regionIndexCode);
        List<Map> maps = HikCamerasResoures.getCameras(camerasRequest);
        if (maps == null || maps.size() == 0) {
            return R.failure("没有监控点");
        }
        return R.success(maps);
    }

}